package com.zzyl.controller.manager;

import com.zzyl.base.PageBean;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DevicePropertyStatusVo;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import com.zzyl.vo.QueryThingModelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api(tags = "Iot设备管理")
@RequestMapping("/iot")
public class DeviceController {
    @Autowired
    DeviceService deviceService;

    @SneakyThrows
    @ApiOperation("产品列表数据同步")
    @PostMapping("/syncProductList")
    public ResponseResult<Void> syncProductList() {

        log.info("同步产品列表数据");
        deviceService.syncProductList();
        return ResponseResult.success();
    }

    @ApiOperation("查询所有产品列表")
    @GetMapping("/allProduct")
    public ResponseResult<List<ProductVo>> allProduct() {
        log.info("查询所有产品列表");
        return ResponseResult.success(deviceService.allProduct());
    }

    @ApiOperation("注册设备")
    @PostMapping("/RegisterDevice")
    public ResponseResult<Void> registerDevice(@RequestBody DeviceDto deviceDto) {
        log.info("注册设备");
        deviceService.registerDevice(deviceDto);
        return ResponseResult.success();
    }

    @ApiOperation("分页查询设备")
    @GetMapping("/pageQueryDevice")
    public ResponseResult<PageBean<DeviceVo>> PagequeryDevice(DevicePageQueryDto Dto) {
        log.info("分页查询设备");
        return ResponseResult.success(deviceService.PagequeryDevice(Dto));
    }

    @ApiOperation("查询设备详情")
    @PostMapping("/QueryDeviceDetail")
    public ResponseResult<DeviceVo> queryDeviceDetail(@RequestBody DeviceDto Dto) {
        log.info("查询设备详情");
        return ResponseResult.success(deviceService.QueryDeviceDetail(Dto));
    }
    //============================================================== 课外作业

    @ApiOperation(value = "查看指定产品的物模型数据")
    @PostMapping("/QueryThingModelPublished")
    public ResponseResult<QueryThingModelVo> QueryThingModelPublished(@RequestBody DeviceDto Dto) {
        log.info("查看指定产品的物模型数据");

        return ResponseResult.success(deviceService.QueryThingModelPublished(Dto));
    }

    @ApiOperation(value = "查询指定设备的物模型运行状态")
    @PostMapping("/QueryDevicePropertyStatus")
    public ResponseResult<DevicePropertyStatusVo> QueryDevicePropertyStatus(@RequestBody DeviceDto Dto) {
        log.info("查询指定设备的物模型运行状态");
        return ResponseResult.success(deviceService.QueryDevicePropertyStatus(Dto));
    }

    @ApiOperation(value = "修改设备备注名称")
    @PostMapping("/UpdateDevice")
    public ResponseResult<Void> UpdateDevice(@RequestBody DeviceDto Dto) {
        log.info("修改设备备注名称");
        deviceService.UpdateDevice(Dto);
        return ResponseResult.success();
    }

    @ApiOperation(value = "删除设备")
    @DeleteMapping("/DeleteDevice")
    public ResponseResult<Void> DeleteDevice(@RequestBody DeviceDto Dto) {
        deviceService.deleteDevice(Dto);
        return ResponseResult.success();
    }
}
